package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bp.domain.QuickReply;
import com.naiterui.ehp.bs.doctor.dao.IQuickReplyDao;
import com.naiterui.ehp.bs.doctor.repository.IQuickReplyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class AdQuickReplyDaoImpl  implements IQuickReplyDao {

    @Autowired
    private IQuickReplyRepository quickReplyRepository;

    @Override
    public void save(QuickReply quickReply) {
        quickReplyRepository.save(quickReply);
    }

    @Override
    public void removeById(Integer id) {
        quickReplyRepository.removeById(id);
    }

    @Override
    public List<QuickReply> findQuickReplyList(Long doctorId) {
        return quickReplyRepository.findByDoctorIdOrderByCreatedAtDesc(doctorId);
    }

    @Override
    public void saveBatch(List<String> replys, Long doctorId) {
        if (replys == null || replys.size() <= 0) {
            return;
        }
        List<QuickReply> list = new ArrayList<>();
        for (String reply : replys) {
            QuickReply replyBean = new QuickReply();
            replyBean.setDoctorId(doctorId);
            replyBean.setContent(reply);
            replyBean.setCreatedAt(new Date());
            replyBean.setType(QuickReply.TYPE_CONSULT_SESSION);
            list.add(replyBean);
        }
        quickReplyRepository.save(list);
    }

}
